package org.example.sys.controller;


import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.sys.entity.SysGame;
import org.example.sys.entity.SysInvest;
import org.example.sys.entity.SysPlay;
import org.example.sys.service.ISysGameService;
import org.example.sys.service.ISysInvestService;
import org.example.sys.service.ISysPlayService;
import org.example.utlis.BaseController;
import org.example.utlis.ResponseUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 充值表 前端控制器
 * </p>
 *
 * @author Joey
 * @since 2021-02-27
 */
@RestController
@RequestMapping("/sys/invest")
@Slf4j
public class SysInvestController extends BaseController<SysInvest> {
    @Resource
    ISysGameService sysGameService;
    @Resource
    ISysInvestService sysInvestService;
    @Resource
    ISysPlayService sysPlayService;

    @ApiOperation(value = "查询充值列表")
    @GetMapping("/listData")
    public ResponseUtil listData(){
        try {
            List<SysInvest> list = sysInvestService.list();
            for(SysInvest item:list){
                SysGame game = sysGameService.getById(item.getGameId());
                if(game!=null){
                    item.setGameName(game.getGameName());
                }
                SysPlay play = sysPlayService.getById(item.getPlayId());
                if(play!=null){
                    item.setPlayName(play.getPlayName());
                }
            }
            return ResponseUtil.success(list);
        }catch (Exception e){
            log.error("查询充值列表出错",e);
            return ResponseUtil.error();
        }
    }

    @Override
    public IService<SysInvest> getService() {
        return sysInvestService;
    }
}

